home *** CD-ROM | disk | FTP | other *** search
- Path: sooner.net!usenet
- From: Eddie Bush <edwbush@sooner.net>
- Newsgroups: comp.lang.c
- Subject: Re: beginner question
- Date: Wed, 03 Apr 1996 03:08:32 -0800
- Organization: sooner.net news site
- Message-ID: <31625C30.12AA@sooner.net>
- References: <4jc3sr$1ggu@uvaix3e1.comp.UVic.CA> <4jdo7l$de2@sparcserver.lrz-muenchen.de> <315AFED2.7466@willows.com> <315F525A.4A1CD496@alcyone.com>
- NNTP-Posting-Host: p22.sooner.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- Erik Max Francis wrote:
- >
- > Tarang Deshpande wrote:
- >
- > > So then what does the following mean:
- > >
- > > struct _FOO
- > > {
- > > int bar;
- > > } FOO;
- > >
- > > struct _FOO s1;
- > > FOO s2;
- > >
- > > Why?
- >
- > This is a compiler error.
-
- I'm sorry. I don't see an error -- just two different variables of the same type that happen to
- be declared using two different (and correct) methods.
-
- >
- > struct _FOO { int bar; } FOO;
- >
- > declares a structure called struct _FOO and an instance of that structure FOO.
- > The further declaration
-
- The initial declaration of the structure doesn't make available FOO for manipulation. FOO is a
- type. ...isn't it? I always understood that 'struct _FOO' is the 'tag name' (the name of the
- structure', and that FOO would be a type which you have defined (by the typedef struct _FOO) to
- be the structure _FOO.
-
- >
- > FOO s2;
- >
- > and is tantamount to saying
- >
- > int x, y;
- > x y;
- >
- > What you're probably _actually_ seeing is
- >
- > typedef struct _FOO { int bar; } FOO;
- >
- > which defines the type FOO which is an alias for struct _FOO.
- >
- > --
- > Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max@alcyone.com
- > San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
- > H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
- > Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
- > "Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_
-
- Maybe I just do things differently. I put all of my declarations of types into a *.h file
- and reference them from that by '#include "mytype.h"'. I don't see a difference though. You
- aren't declaring any variables -- only variable types.
-
- Also, from what I understand, you would do it like this:
-
- typedef struct {
- int num;
- } FOOBAR;
-
- This would be if you intended to use the type statically. Or, you could:
-
- typedef struct FOO {
- int num;
- } *BAR;
-
- if you happened to want to allocate the variable dynamically.
-
- Notice, that I left the 'tag name' off of the variable which I intend to use statically. That is
- because it is not needed -- you only need it to allocate memory dynamically:
-
- BAR new_bar;
-
- new_bar = (BAR) malloc (sizeof (struct FOO));
-
- Maybe this helps (and doesn't confuse) someone. I felt very confused by the string of preceding
- messages -- maybe it's the time of day. Who knows...
-
- Later, and Good Luck!
-
- Eddie Bush
-